/*
 * \brief  Interface of the printf backend
 * \author Norman Feske
 * \date   2006-04-08
 */

/*
 * Copyright (C) 2006-2009 Norman Feske
 * Genode Labs, Feske & Helmuth Systementwicklung GbR
 *
 * This file is part of the Genode OS framework, which is distributed
 * under the terms of the GNU General Public License version 2.
 */

#ifndef _INCLUDE__BASE__PRINTF_H_
#define _INCLUDE__BASE__PRINTF_H_

#include <stdarg.h>

namespace Genode {

	/**
	 * For your convenience...
	 */
	void  printf(const char *format, ...);
	void vprintf(const char *format, va_list);

	/** Format-string checker */
	extern "C" void format_check(const char *format, ...) __attribute__((format(printf, 1, 2)));
}

#define ESC_DBG  "\033[33m"
#define ESC_WRN  "\033[34m"
#define ESC_ERR  "\033[31m"
#define ESC_END  "\033[0m"

#define PDBG(args...)                                \
	do {                                             \
		if (0) Genode::format_check(args);           \
		Genode::printf("%s: ", __PRETTY_FUNCTION__); \
		Genode::printf(ESC_DBG);                     \
		Genode::printf(args);                        \
		Genode::printf(ESC_END"\n");                 \
	} while (0)

#define PWRN(args...)                                \
	do {                                             \
		if (0) Genode::format_check(args);           \
		Genode::printf("%s: ", __PRETTY_FUNCTION__); \
		Genode::printf(ESC_WRN);                     \
		Genode::printf(args);                        \
		Genode::printf(ESC_END"\n");                 \
	} while (0)

#define PERR(args...)                                \
	do {                                             \
		if (0) Genode::format_check(args);           \
		Genode::printf("%s: ", __PRETTY_FUNCTION__); \
		Genode::printf(ESC_ERR);                     \
		Genode::printf(args);                        \
		Genode::printf(ESC_END"\n");                 \
	} while (0)

#endif /* _INCLUDE__BASE__PRINTF_H_ */
